package com.ozo.boot.manage.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ozo.boot.common.base.model.*;
import com.ozo.boot.common.base.model.BasePage;
import com.ozo.boot.common.base.model.PageResult;
import com.ozo.boot.common.base.model.ResultVO;
import com.ozo.boot.common.log.annotation.OperateLog;
import com.ozo.boot.manage.pojo.dto.ChangeStatusDTO;
import com.ozo.boot.manage.pojo.dto.SysPostQueryDTO;
import com.ozo.boot.manage.pojo.dto.SysPostSaveDTO;
import com.ozo.boot.manage.pojo.vo.SysPostVO;
import com.ozo.boot.manage.service.ISysPostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

import java.util.List;

/**
 * 岗位 前端控制器
 *
 * @author qiangesoft
 * @since 2024-11-16 23:43:39
 */
@Tag(name = "岗位")
@RequiredArgsConstructor
@RestController
@RequestMapping("/manage/post")
public class SysPostController {

    private final ISysPostService sysPostService;

    @OperateLog(value = "添加岗位", module = "岗位")
    @SaCheckPermission("manage:post:add")
    @Operation(summary = "添加岗位")
    @PostMapping("/add")
    public ResultVO<Void> add(@RequestBody @Valid SysPostSaveDTO saveDTO) {
        sysPostService.add(saveDTO);
        return ResultVO.success();
    }

    @OperateLog(value = "删除岗位", module = "岗位")
    @SaCheckPermission("manage:post:remove")
    @Operation(summary = "删除岗位")
    @DeleteMapping("/remove")
    public ResultVO<Void> remove(@RequestBody @Valid BaseBatchDTO<Long> batchDTO) {
        sysPostService.remove(batchDTO);
        return ResultVO.success();
    }

    @OperateLog(value = "编辑岗位", module = "岗位")
    @SaCheckPermission("manage:post:edit")
    @Operation(summary = "编辑岗位")
    @PutMapping("/edit")
    public ResultVO<Void> edit(@RequestBody @Validated(value = BaseValidDTO.edit.class) SysPostSaveDTO saveDTO) {
        sysPostService.edit(saveDTO);
        return ResultVO.success();
    }

    @SaCheckPermission("manage:post:page")
    @Operation(summary = "岗位分页")
    @GetMapping("/page")
    public ResultVO<PageResult<SysPostVO>> page(@Valid BasePage basePage, SysPostQueryDTO queryDTO) {
        return ResultVO.success(sysPostService.page(basePage, queryDTO));
    }

    @OperateLog(value = "修改状态", module = "岗位")
    @SaCheckPermission("manage:post:changeStatus")
    @Operation(summary = "修改状态")
    @PutMapping("/changeStatus")
    public ResultVO<Void> changeStatus(@RequestBody @Valid ChangeStatusDTO statusDTO) {
        sysPostService.changeStatus(statusDTO);
        return ResultVO.success();
    }

    @Operation(summary = "岗位列表")
    @GetMapping("/list")
    public ResultVO<List<SysPostVO>> list(SysPostQueryDTO queryDTO) {
        return ResultVO.success(sysPostService.list(queryDTO));
    }

}